package cn.yuanqiao.web.controller.manage;

import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.manage.domain.YqdaCoderuleModel;
import cn.yuanqiao.manage.service.IYqdaCoderuleModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.List;

/**
 * manageController
 * 
 * @author yuanqiao
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/manage/coderule")
public class YqdaCoderuleModelController extends BaseController
{
    @Autowired
    private IYqdaCoderuleModelService yqdaCoderuleModelService;

    /**
     * 查询manage列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:coderule:list")
    @Log(title = "查询档号定义模板列表", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(YqdaCoderuleModel yqdaCoderuleModel)
    {
        startPage();
        List<YqdaCoderuleModel> list = yqdaCoderuleModelService.selectYqdaCoderuleModelList(yqdaCoderuleModel);
        return getDataTable(list);
    }

    /**
     * 导出manage列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:coderule:export")
    @Log(title = "导出档号定义模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqdaCoderuleModel yqdaCoderuleModel)
    {
        List<YqdaCoderuleModel> list = yqdaCoderuleModelService.selectYqdaCoderuleModelList(yqdaCoderuleModel);
        ExcelUtil<YqdaCoderuleModel> util = new ExcelUtil<YqdaCoderuleModel>(YqdaCoderuleModel.class);
        util.exportExcel(response, list, "manage数据");
    }

    /**
     * 获取manage详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manage:coderule:query")
    @Log(title = "获取档号定义模板详细信息", businessType = BusinessType.SELECT)
    @GetMapping(value = "/{Id}")
    public AjaxResult getInfo(@PathVariable("Id") Long Id)
    {
        return success(yqdaCoderuleModelService.selectYqdaCoderuleModelById(Id));
    }

    /**
     * 新增manage
     */
    //@PreAuthorize("@ss.hasPermi('manage:coderule:add")
    @Log(title = "新增档号定义模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody YqdaCoderuleModel yqdaCoderuleModel) throws ParseException {
        String result=yqdaCoderuleModelService.insertYqdaCoderuleModel(yqdaCoderuleModel);
        if("ok".equals(result)){
            return AjaxResult.success();
        }else{
            return AjaxResult.error(result);
        }
    }

    /**
     * 修改manage
     */
    //@PreAuthorize("@ss.hasPermi('manage:coderule:edit")
    @Log(title = "修改档号定义模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqdaCoderuleModel yqdaCoderuleModel) throws ParseException {
        String result=yqdaCoderuleModelService.updateYqdaCoderuleModel(yqdaCoderuleModel);
        if("ok".equals(result)){
            return AjaxResult.success();
        }else{
            return AjaxResult.error(result);
        }
    }

    /**
     * 删除manage
     */
    //@PreAuthorize("@ss.hasPermi('manage:coderule:remove")
    @Log(title = "删除档号定义模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{Ids}")
    public AjaxResult remove(@PathVariable Long[] Ids)
    {
        return toAjax(yqdaCoderuleModelService.deleteYqdaCoderuleModelByIds(Ids));
    }
}
